package io.github.uicdb.badskill.block;

import io.github.uicdb.badskill.BSRegistries;
import io.github.uicdb.badskill.PlayerSkillCapability;
import io.github.uicdb.badskill.PlayerSkillCapabilityProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.TickingBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.util.NonNullConsumer;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;
import java.util.function.Predicate;

public class DisableEntity extends BlockEntity {
    public DisableEntity( BlockPos blockPos, BlockState blockState) {
        super(BSRegistries.BLOCKENTITY_DISABLE.get(), blockPos, blockState);
    }
    protected int getRange(){
        return 200;
    }


    public void tick(@NotNull Level level) {

        if (!level.isClientSide) {
            AABB aabb = new AABB(-getRange(), -getRange(), -getRange(), getRange(), getRange(), getRange()).move(getBlockPos());
            level.getServer().getPlayerList().getPlayers().stream().filter(serverPlayer -> aabb.contains(serverPlayer.position())).forEach(serverPlayer -> serverPlayer.getCapability(PlayerSkillCapabilityProvider.CAPABILITY).ifPresent(capability -> capability.disableAll(40)));

        }
    }
}
